package com.jj.jni;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.lang.reflect.Field;

/**
 * Copyrights: QidianGroup@JJ
 *
 * @author: LuHan
 * @date: 2018/1/18, 10:10
 */
public class FoobarDemo {
    private static Logger logger = LoggerFactory.getLogger(FoobarDemo.class);

    static {
        setSysEnv("java.library.path", "D:\\workspace\\act_root\\act\\battleserver\\lib");
    }

    public static void installDLL(String lualib) {
        File libDir = new File(lualib);
        String libPath = libDir.getAbsolutePath();
        System.load(libPath);
        logger.debug(lualib + " has been loadded!");
    }

    public static void setSysEnv(String prop, String value) {
        System.setProperty(prop, value);
        try {
            Field fieldSysPath;
            fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
            fieldSysPath.setAccessible(true);
            fieldSysPath.set(null, null);
        } catch (Throwable t) {
            logger.error("exception:", t);
        }
    }

    public static void main(String[] args) {
        Foobar.add(1,1);
    }
}
